<!DOCTYPE html>
<html lang="en">
<head>
  
<meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- <link rel="shortcut icon" href="http://favicon.ico"> -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">


  <link rel="stylesheet" href="http://106.12.207.1:8080/wuliucommon/css/sm.min.css">
  <link rel="stylesheet" href="http://106.12.207.1:8080/wuliucommon/css/sm-extend.min.css">
  <script type="text/javascript" src="http://106.12.207.1:8080/wuliucommon/common/common/common.js"></script>
  <style>
    .content{
      background-color: white;
      font-size: 15px;
    }
    .content-padded{
      padding-bottom: 0.5rem;
    }
    .row{
      padding-bottom: 0.2rem;
    }
    .detailsStatus{
      text-align: right; 
      font-size: 15px;
      color: red;
    }
    .needHide{
      display: none;
    }
    #buttonPos{
      display: flex;
      justify-content: space-around;
    }
    .theButton{
      border: none;
      border-radius: 3px;
      padding: 0.4rem 0.9rem;
      font-size: 16px;
      color: white;
    }
    /* 保存按钮 */
    #saveButton{
      background-color: #169BD5;
    }
    /* 复制按钮 */
    #copyButton{
      background-color: #8080FF;
    }
    /* 下达按钮 */
    #issuedButton{
      background-color: #D9001B;
    }
    /* 撤销按钮 */
    #undoButton{
      background-color: #919492;
    }
    /* 追踪按钮 */
    #trackButton{
      background-color: rgb(0, 225, 255);
    }
    /* 终止按钮 */
    #overButton{
      background-color: #D9001B;
    }
    /* 删除按钮 */
    #deleteButton{
      background-color: #C280FF;
    }
    .bar{
      background-color: #c49c22;
    }
    .bianbai{
      color: white;
    }

    #testdiv{
      width:100%;
      height:3%;
      background-color: lightgray;
      position: absolute;
      float: bottom;
      top:97%;
      left:0px;
      z-index: 5000;

    }
 
  </style>
</head>
<body>
  
  <div class="page-group">
    <div class="page">
        <header class="bar bar-nav" >
            <a class="icon  pull-left bianbai" style="font-size: 0.75rem;" onclick="goback()">返回</a>
            <a class="icon   pull-right"></a>
            <h1 class="title bianbai">详情</h1>
        </header>

        <div class="content">
          <div class="content-padded grid-demo">

            <div class="detailsStatus">待下达</div>
            <div class="row no-gutter">
              <div><span>销售合同编号：</span><span id="code"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>公司名称：</span><span id="companyName"></span></div>
            </div>
            <div class="row no-gutter">
                <div><span>发库地区：</span>
                    <span class="reservoir needHide" id="reservoirText"></span>
                    <input type="text" class="reservoir needHide" id="reservoirInput">
                    <!-- <input type="text" id='picker'/> -->
                </div>
            </div>

            <div class="row no-gutter">
              <div><span>计划发货时间：</span><input id="deliveryDate" type="text" data-toggle='date'/></div>
            </div>
            <div class="row no-gutter">
                <div><span>项目名称：</span>
                  <span class="projectName needHide" id="projectNameText"></span>
                  <input type="text" class="projectName needHide" id="projectNameInput">
                </div>
            </div>
            <div class="row no-gutter">
              <div class="col-50"><span>货物类型：</span><span id="goodsType"></span></div>
              <div class="col-50"><span>货物名称：</span><span id="goodsName"></span></div>
            </div>
            <div class="row no-gutter">
              <div class="col-50"><span>货物品牌：</span><span id="brand"></span></div>
              <div class="col-50"><span>货物规格：</span><span id="kind"></span></div>
            </div>
            <div class="row no-gutter">
              <div class="col-50"><span>合同数量：</span><span id="contractQty"></span>&nbsp;t</div>
              <div class="col-50 needHide" id="shenghe"><span>剩余核发：</span><span id="noQty"></span>&nbsp;t</div>
            </div>
            <div class="row no-gutter">
              <div class="col-50" style="display: flex;justify-items: start;"><span>计划数量：</span>
                <span class="planQty" id="planQtyText"></span>&nbsp;t
              </div>
              <div class="col-50"><span>下达数量：</span>
                <span  class="needHide" id="qty"></span>
                <input type="text" class="needHide" id="qtyInput" style="width:3rem;">
                &nbsp;t
              </div>
            </div>            
            <div class="row no-gutter">
              <div class="col-50"><span>提货方式：</span><span id="pickup"></span></div>
              <div class="col-50"><span>运输方式：</span><span id="delivery"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>计划到货时间：</span><span id="takeDate"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>收货地点：</span><span id="takePlace"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>收货单位：</span><span id="receiver"></span></div>
            </div>
            <div class="row no-gutter">
              <div class="col-50"><span>收货人：</span><span id="receiverPerson"></span></div>
              <div class="col-50"><span>联系方式：</span><span id="receiverMobile"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>制单人：</span><span id="formMaker"></span></div>
            </div>
            <div class="row no-gutter">
                <div><span>制单时间：</span><span id="formDate"></span></div>
            </div>
            <div class="row no-gutter">
              <div><span>销售人：</span><span id="sellPeople"></span></div>
            </div>
            <div class="row no-gutter">
              <div>备注：</div>
              <div>
                <textarea name="" class="remarks" id="remarksInput" rows="3" style="width:100%;"></textarea>
              </div>
            </div>
            <div id="buttonPos">
                <!-- 待下达 -->
                <button class="theButton needHide" id="issuedButton" onclick="toIssued()">下达</button>
                <!-- 已下达 -->
                <button class="theButton needHide" id="undoButton" onclick="toUndo()">撤销</button>
                <button class="theButton needHide" id="overButton" onclick="toOver()">终止</button>
                <!-- 公共 -->
                <button class="theButton needHide" id="deleteButton" onclick="toDelete()">删除</button>

                <button class="theButton needHide" id="trackButton" onclick="planTracking()">跟踪</button>
              </div>
          </div>
        </div>

        
    </div>
  </div>

<script type="text/javascript" src="http://106.12.207.1:8080/wuliucommon/js/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">var $$ =jQuery.noConflict();</script>

<script type='text/javascript' src='http://106.12.207.1:8080/wuliucommon/zepto/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='http://106.12.207.1:8080/wuliucommon/js/js/sin.js' charset='utf-8'></script>
<script src="http://106.12.207.1:8080/wuliucommon/js/js/swiper/ser.js"></script>
<script type="text/javascript">


// 全局
// 详情数据（因多个接口需要调取数据，故作为全局变量）
var detailData = '';
// 判断页面来源类型 (待下达/已下达)(部署页面 / 删除 时有用到)
var cid = "";
var ctype = "plan";//默认为待下达  order已下达
var loadingdata = false;
var trackingId = ''



function testdivclick(){
  native_goto("local/planTracking");
}

// 整理页面（根据链接不同的来源来调整页面显示）
function settlePage(){
  // 提前将需要隐藏的全部隐藏
  $$(".needHide").hide();
  
    // 模拟来源
    if(ctype == 'plan'){
      // 右上角状态显示
      $$(".detailsStatus").text('待下达');

      // 所有按钮yi全部隐藏，防止其他途径进入的违规操作
      $$("#saveButton").show();
      // $$("#copyButton").show();
      $$("#issuedButton").show();
      $$("#deleteButton").show();
      
      // 剩余核发
      $$("#shenghe").show();

      // 显示发货地区
      // $$('#reservoirInput').show();
      $$('#reservoirText').show();

      // 显示项目名称
      // $$('#projectNameInput').show();
      $$('#projectNameText').show();

      // 显示备注
      $$('#remarksInput').attr("readonly",false);
      // 下达数量
      $$('#qtyInput').show();
      
    }else if(ctype == 'order'){
      // 右上角状态显示
      $$(".detailsStatus").text('已下达');
      
      // 所有按钮yi全部隐藏，防止其他途径进入的违规操作
      $$("#undoButton").show();
      $$("#overButton").show();
      $$("#deleteButton").show();
      $$("#trackButton").show(); // 追踪按钮
      

      // 显示发货地区
      $$('#reservoirText').show();
      // 显示项目名称
      $$('#projectNameText').show();
      // 显示备注
      $$('#remarksInput').attr("readonly",true);
      // 下达数量
      $$('#qty').show();
    }else{
      // alert('亲~违规操作哦！')
    }
}


// 模拟数据并写入
function toWrite(detailData) {

  trackingId = detailData.planId

  if(!isNotNull(detailData)){
    return;
  }


  // alert(typeof(detailData))
  // 销售合同编号 = code
  if(detailData.code){
    $$("#code").text(detailData.code);
  }
  // 公司名称 = companyName
  // ???????????????
  if(detailData.companyName){
    $$("#companyName").text(detailData.companyName);
  }
  // 发货库区 = reservoir // 可改
  if(detailData.reservoir){
    $$(".reservoir").text(detailData.reservoir);
  }
  // 计划发货时间 = deliveryDate
  if(detailData.deliveryDate){
    $$("#deliveryDate").val(detailData.deliveryDate);
  }
  // 项目名称 = projectName // 可改
  if(detailData.projectName){
    $$(".projectName").text(detailData.projectName);
  }
  // 货物类型 = goodsType 需获取名称
  // ???????????????
  if(detailData.goodsType){
    $$("#goodsType").text(detailData.goodsType);
  }
  // 货物名称 = goodsName
  if(detailData.goodsName){
    $$("#goodsName").text(detailData.goodsName);
  }
  // 货物品牌 = brand
  if(detailData.brand){
    $$("#brand").text(detailData.brand);
  }
  // 货物规格 = kind
  if(detailData.kind){
    $$("#kind").text(detailData.kind);
  }
  // 合同数量 = contractQty 
  if(detailData.contractQty ){
    if(detailData.contractQty){
      $$("#contractQty ").text(detailData.contractQty);
    }
  }
  // 剩余核发 = noQty
  if(detailData.noQty){
    if(detailData.noQty == ".00"){
      $$("#noQty").text(0);
    }else{
      $$("#noQty").text(detailData.noQty);
    }
  }
  // 计划数量 = planQty // 可改
  if(detailData.planQty){
    $$("#planQtyText").text(detailData.planQty);
  }
  // 下达数量 = qty
  var qty_val = 0;
  if(isNotNull(detailData.qty)){
    qty_val = detailData.qty;
  }
  $$("#qty").text(qty_val);
  $$("#qtyInput").val(qty_val);
  
  
  // 提货方式 = pickup 需获取名称
  // ???????????????
  if(detailData.pickup){
    $$("#pickup").text(detailData.pickup);
  }
  // 运输方式 = delivery 需获取名称
  // ???????????????
  if(detailData.delivery){
    $$("#delivery").text(detailData.delivery);
  }
  // 计划到货时间 = takeDate
  if(detailData.takeDate){
    $$("#takeDate").text(detailData.takeDate);
  }
  // 收货地点 = takePlace
  if(detailData.takePlace){
    $$("#takePlace").text(detailData.takePlace);
  }
  // 收货单位 = receiver
  if(detailData.receiver){
    $$("#receiver").text(detailData.receiver);
  }
  // 收货人 = receiverPerson
  if(detailData.receiverPerson){
    $$("#receiverPerson").text(detailData.receiverPerson);
  }
  // 联系方式 = receiverMobile
  if(detailData.receiverMobile){
    $$("#receiverMobile").text(detailData.receiverMobile);
  }
  // 制单人 = formMaker
  if(detailData.formMaker){
    $$("#formMaker").text(detailData.formMaker);
  }
  // 制单时间 = formDate
  if(detailData.formDate){
    $$("#formDate").text(detailData.formDate);
  }
  // 销售人 = sellPeople
  if(detailData.sellPeople){
    $$("#sellPeople").text(detailData.sellPeople);
  }
  // 备注 = remarks // 可改
  if(detailData.remarks){
    $$("#remarksInput").text(detailData.remarks);
  }
}    


// 保存事件
function toSave() {
  // 发货库区
  // var str_reservoir = $$('#reservoirInput').val();
  // 隐藏项目名称
  var str_projectName = $$('#projectNameInput').val();
  // 隐藏计划数量
  var str_planQty= $$('#planQtyInput').val();
  // 隐藏备注
  var str_remarks = $$('#remarksInput').val();

  var time = $$('#deliveryDate').val();

  // 调接口
  let param = {
    "num": str_planQty,
    // ???????????????
    "plan_id": cid,
    // "resename": str_reservoir,
    // "reseid": '', // 库区id
    // ???????????????
    "time": time,
    "remark": str_remarks
    // ???????????????
  }
  let url = 'delivery_order/wlDeliveryOrder/api/edit_attr';
  net_request('post',url,param,saveformSuccessCallBack,errorCallBack);
}



function saveformSuccessCallBack(data) {
  // native_showdialog("aaa"+JSON.stringify(data));
  if(data && data.state == '0'){
      $.toast("保存成功");
   }else{
      // $.toast("操作失败");
      native_showdialog(data.msg);
      
   }
}


// 复制事件
function toCopy() {
  // 调接口
  let param = {
  }
  let url = 'delivery_order/wlDeliveryOrder/api/plan_copy'+SESSIONID+'?id='+cid;
  net_request('get',url,param,copySuccessCallBack,errorCallBack);
}
function copySuccessCallBack(data) {
   if(data && data.state == '0'){
      $.toast("复制成功，可去列表中查看");
   }else{
      $.toast("操作失败");
   }
}


// 下达事件
function toIssued() {

  var numval = $("#qtyInput").val();

  if(!isNotNull(numval)){
      //$.alert("");
      native_showdialog("计划下达数量不能为空");
      return;
  }else{
    var dval = parseFloat(numval);
    if(dval == 0){
      native_showdialog("计划下达数量不能为0");
      return;
    }
  }

  var sendtime = $("#deliveryDate").val();
  // 调接口
  let param = {
  }
  let url = 'delivery_order/wlDeliveryOrder/api/issued'+SESSIONID+'?plan_id='+cid+"&num="+numval+"&sendtime="+sendtime;
  net_request('get',url,param,issuedSuccessCallBack,errorCallBack);
}
function issuedSuccessCallBack(data) {
  if(data && data.state == '0'){
      $.toast("下发成功");
      native_goto('local/finish');
   }else{
      // $.toast("操作失败");
      native_showdialog(data.msg);
      // native_showdialog("ccc");
   }
}


// 撤销事件
function toUndo() {
  $.confirm('确定撤销？', '撤销', function () {
      // 调接口
      let param = {
      }
      let url = 'delivery_order/wlDeliveryOrder/api/deleteBack'+SESSIONID+'?order_id='+cid;
      net_request('get',url,param,undoSuccessCallBack,errorCallBack);
  });
}
function undoSuccessCallBack(data) {
  if(data && data.state == '0'){
      $.toast("撤销成功");
      native_goto('local/finish');
   }else{
      // $.toast("操作失败");
      native_showdialog(data.msg);
      // native_showdialog("ddd");
   }
}


// 终止事件
function toOver() {
  $.prompt('请输入终止数量', '终止',
    function (value) {
      overJiekou(value)
    },
    function (value) {
      // 无操作
      // $.alert('Your name is "' + value + '". You clicked Cancel button');
    }
  );
  return;
}
// 终止接口
function overJiekou(NUM) {
  // 调接口
  let param = {
  }
  let url = 'delivery_order/wlDeliveryOrder/api/stop'+SESSIONID+'?order_id='+cid+'&stopnum='+NUM;
  net_request('get',url,param,overSuccessCallBack,errorCallBack);
}
function overSuccessCallBack(data) {
    if(data && data.state == '0'){
      $.toast("强制终止成功");
      native_goto('local/finish');
   }else{
      // $.toast("操作失败");
      native_showdialog(data.msg);
   }
}
 

// 删除事件
function toDelete() {
  if(ctype == 'plan'){
    deleteWait();
  }else if(ctype == 'order'){
    deleteOver();
  }
}

function planTracking() {
  native_goto("local/planTracking?planId=" + trackingId);
}
// 删除待下达接口
function deleteWait() {
  let param = {}
  let url = 'delivery_order/wlDeliveryOrder/api/delete_plan'+SESSIONID+'?plan_id='+cid;
  net_request('get',url,param,deleteWaitSuccessCallBack,errorCallBack);
}
function deleteWaitSuccessCallBack(data) {
  if(data && data.state == '0'){
      $.toast("删除成功");
      native_goto('local/finish');
   }else{
      $.toast("操作失败");
   }
}

// 删除已下达接口
function deleteOver() {
  let param = {
  }
  let url = 'delivery_order/wlDeliveryOrder/api/delete_order'+SESSIONID+'?order_id='+cid;
  net_request('get',url,param,deleteOverSuccessCallBack,errorCallBack);
}
function deleteOverSuccessCallBack(data) {
  if(data && data.state == '0'){
      $.toast("删除成功");
      native_goto('local/finish');
   }else{
      $.toast("操作失败");
   }
}





//成功函数回调 页面
function dataSuccessCallBack(data){
  // alert(JSON.stringify(data));
  if (isNotNull(data)) {
      if(ctype == 'plan'){
        toWrite(data.pdata);
      }else if(ctype == 'order'){
        toWrite(data.odata);
      }
  }else{
    $.toast("数据获取异常");
  }
}

//失败函数
function errorCallBack(){
}

//获取数据
function getData(){

  var param = {}
  var url = "delivery_order/wlDeliveryOrder/api/plandetails"+SESSIONID+"?type="+ctype+"&cid="+cid;
  net_request('get',url,param,dataSuccessCallBack,errorCallBack);
}


function getParams(data){
  var jodata = urlParamParseJson(data);
     if(isNotNull(jodata) && isNotNull(jodata.cid) && isNotNull(jodata.type)){//
        cid = jodata.cid;
        ctype = jodata.type;
        
        // 修正页面
        settlePage();
        
        //防止数据被加载两遍
        if(!loadingdata){
          getData();
          loadingdata = true;
        }
        

        // 写入详情数据
        // toWrite();
     }

}

// 返回
function goback(params) {
  if(ctype == 'order'){
    localStorage.setItem("lasttype",1);
  }else{
    localStorage.setItem("lasttype",0);
  }
  native_goto('local/finish');
}

$(function () {
    $.init();
    
});

  </script>
</body>
</html>